home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 June / Cd Pc Users 9.iso / prog / inst / traydemo / tray.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-12  |  10.0 KB  |  336 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "VB4 Tray"
  5.    ClientHeight    =   2970
  6.    ClientLeft      =   1425
  7.    ClientTop       =   2250
  8.    ClientWidth     =   5265
  9.    Height          =   3375
  10.    Left            =   1365
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2970
  15.    ScaleWidth      =   5265
  16.    ShowInTaskbar   =   0   'False
  17.    Top             =   1905
  18.    Width           =   5385
  19.    Begin VB.CheckBox chkFlash 
  20.       Caption         =   "Flash"
  21.       Height          =   255
  22.       Left            =   180
  23.       TabIndex        =   11
  24.       Top             =   600
  25.       Width           =   795
  26.    End
  27.    Begin VB.Timer Timer1 
  28.       Interval        =   1000
  29.       Left            =   4080
  30.       Top             =   1020
  31.    End
  32.    Begin VB.PictureBox Picture1 
  33.       Height          =   315
  34.       Left            =   120
  35.       ScaleHeight     =   255
  36.       ScaleWidth      =   315
  37.       TabIndex        =   10
  38.       Top             =   1620
  39.       Width           =   375
  40.    End
  41.    Begin VB.CommandButton cmdUnload 
  42.       Caption         =   "Unload"
  43.       Height          =   375
  44.       Left            =   4080
  45.       TabIndex        =   9
  46.       Top             =   540
  47.       Width           =   1095
  48.    End
  49.    Begin VB.CommandButton cmdClose 
  50.       Caption         =   "Close"
  51.       Height          =   375
  52.       Left            =   4080
  53.       TabIndex        =   8
  54.       Top             =   60
  55.       Width           =   1095
  56.    End
  57.    Begin VB.CommandButton cmdChangeTip 
  58.       Caption         =   "Change"
  59.       Height          =   315
  60.       Left            =   3120
  61.       TabIndex        =   5
  62.       Top             =   1200
  63.       Width           =   735
  64.    End
  65.    Begin VB.TextBox txtTip 
  66.       Height          =   315
  67.       Left            =   60
  68.       MaxLength       =   63
  69.       TabIndex        =   4
  70.       Text            =   "This is the tooltip"
  71.       Top             =   1200
  72.       Width           =   3015
  73.    End
  74.    Begin VB.OptionButton Option1 
  75.       Caption         =   "Option1"
  76.       Height          =   255
  77.       Index           =   3
  78.       Left            =   3300
  79.       TabIndex        =   3
  80.       Top             =   600
  81.       Width           =   255
  82.    End
  83.    Begin VB.OptionButton Option1 
  84.       Caption         =   "Option1"
  85.       Height          =   255
  86.       Index           =   2
  87.       Left            =   2700
  88.       TabIndex        =   2
  89.       Top             =   600
  90.       Width           =   255
  91.    End
  92.    Begin VB.OptionButton Option1 
  93.       Caption         =   "Option1"
  94.       Height          =   255
  95.       Index           =   1
  96.       Left            =   2100
  97.       TabIndex        =   1
  98.       Top             =   600
  99.       Width           =   255
  100.    End
  101.    Begin VB.OptionButton Option1 
  102.       Caption         =   "Option1"
  103.       Height          =   255
  104.       Index           =   0
  105.       Left            =   1500
  106.       TabIndex        =   0
  107.       Top             =   600
  108.       Value           =   -1  'True
  109.       Width           =   255
  110.    End
  111.    Begin VB.Label Label5 
  112.       Caption         =   "http://www.mmcsoftware.com"
  113.       BeginProperty Font 
  114.          name            =   "MS Sans Serif"
  115.          charset         =   0
  116.          weight          =   700
  117.          size            =   8.25
  118.          underline       =   0   'False
  119.          italic          =   0   'False
  120.          strikethrough   =   0   'False
  121.       EndProperty
  122.       Height          =   255
  123.       Index           =   4
  124.       Left            =   60
  125.       TabIndex        =   15
  126.       Top             =   2700
  127.       Width           =   3855
  128.    End
  129.    Begin VB.Label Label5 
  130.       Caption         =   "Sample Code by David Warren, MMC Software "
  131.       Height          =   255
  132.       Index           =   3
  133.       Left            =   60
  134.       TabIndex        =   14
  135.       Top             =   2460
  136.       Width           =   3855
  137.    End
  138.    Begin VB.Label Label5 
  139.       Caption         =   "This is a gray icon used for the flash "
  140.       Height          =   195
  141.       Index           =   2
  142.       Left            =   1800
  143.       TabIndex        =   13
  144.       Top             =   2100
  145.       Width           =   2595
  146.    End
  147.    Begin VB.Label Label5 
  148.       Caption         =   "This is the Picturebox that recieves the messages"
  149.       Height          =   195
  150.       Index           =   1
  151.       Left            =   540
  152.       TabIndex        =   12
  153.       Top             =   1680
  154.       Width           =   3855
  155.    End
  156.    Begin VB.Image Image2 
  157.       BorderStyle     =   1  'Fixed Single
  158.       Height          =   540
  159.       Left            =   4500
  160.       Picture         =   "tray.frx":0000
  161.       Top             =   1920
  162.       Width           =   540
  163.    End
  164.    Begin VB.Label Label6 
  165.       Caption         =   "Tooltip in Tray:"
  166.       Height          =   195
  167.       Left            =   120
  168.       TabIndex        =   7
  169.       Top             =   1020
  170.       Width           =   2055
  171.    End
  172.    Begin VB.Label Label5 
  173.       Caption         =   "Select an Icon"
  174.       Height          =   195
  175.       Index           =   0
  176.       Left            =   120
  177.       TabIndex        =   6
  178.       Top             =   120
  179.       Width           =   1155
  180.    End
  181.    Begin VB.Shape Shape1 
  182.       Height          =   915
  183.       Left            =   60
  184.       Top             =   60
  185.       Width           =   3855
  186.    End
  187.    Begin VB.Image Image1 
  188.       Height          =   480
  189.       Index           =   3
  190.       Left            =   3180
  191.       Picture         =   "tray.frx":030A
  192.       Top             =   120
  193.       Width           =   480
  194.    End
  195.    Begin VB.Image Image1 
  196.       Height          =   480
  197.       Index           =   2
  198.       Left            =   2580
  199.       Picture         =   "tray.frx":074C
  200.       Top             =   120
  201.       Width           =   480
  202.    End
  203.    Begin VB.Image Image1 
  204.       Height          =   480
  205.       Index           =   1
  206.       Left            =   1980
  207.       Picture         =   "tray.frx":0B8E
  208.       Top             =   120
  209.       Width           =   480
  210.    End
  211.    Begin VB.Image Image1 
  212.       Height          =   480
  213.       Index           =   0
  214.       Left            =   1380
  215.       Picture         =   "tray.frx":0FD0
  216.       Top             =   120
  217.       Width           =   480
  218.    End
  219. Attribute VB_Name = "Form1"
  220. Attribute VB_Creatable = False
  221. Attribute VB_Exposed = False
  222. Dim IconIndex As Integer, IntDown As Integer
  223. Sub MyPopupmenu(x As Integer, y As Integer)
  224.     hMenu = GetMenu(Form2.hwnd)
  225.     hSubMenu = GetSubMenu(hMenu, 0)
  226.     hTray = FindWindow("Shell_TrayWnd", 0&)
  227.     If hTray > 0 Then
  228.         Dim TrayRect As RECT
  229.         Result = GetWindowRect(hTray, TrayRect)
  230.         lResult = TrackPopupMenu(hSubMenu, TPM_RIGHTALIGN, TrayRect.Right, TrayRect.Bottom, 0&, Form2.hwnd, ByVal 0&)
  231.     End If
  232. End Sub
  233. Private Sub cmdChangeTip_Click()
  234.     Dim iData As NOTIFYICONDATA
  235.     iData.cbSize = Len(iData)
  236.     iData.hwnd = Picture1.hwnd
  237.     iData.uID = 9999
  238.     iData.uFlags = NIF_TIP
  239.     iData.szTip = (txtTip.Text) & Chr$(0)
  240.     Result = Shell_NotifyIcon(NIM_MODIFY, iData)
  241. End Sub
  242. Private Sub cmdClose_Click()
  243.     Me.Hide
  244. End Sub
  245. Private Sub cmdUnload_Click()
  246.     Unload Me
  247. End Sub
  248. Private Sub Form_Load()
  249. '   VB4 Tray
  250. '   Code sample for Visual Basic 4
  251. '   Copyright 
  252.  1996 by David Warren
  253.     Dim iData As NOTIFYICONDATA
  254.     iData.cbSize = Len(iData)
  255.     iData.hwnd = Picture1.hwnd
  256.     iData.uID = 9999
  257.     iData.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP
  258.     iData.uCallbackMessage = WM_LBUTTONDOWN
  259.     iData.hIcon = Image1(0).Picture
  260.     iData.szTip = txtTip.Text & Chr$(0)
  261.     Result = Shell_NotifyIcon(NIM_ADD, iData)
  262.     Me.Hide
  263. End Sub
  264. Private Sub Form_Unload(Cancel As Integer)
  265.     Dim iData As NOTIFYICONDATA
  266.     iData.cbSize = Len(iData)
  267.     iData.hwnd = Picture1.hwnd
  268.     iData.uID = 9999
  269.     Result = Shell_NotifyIcon(NIM_DELETE, iData)
  270.     End
  271. End Sub
  272. Private Sub Image1_Click(Index As Integer)
  273.     Option1(Index).Value = True
  274. End Sub
  275. Private Sub Option1_Click(Index As Integer)
  276.     Dim iData As NOTIFYICONDATA
  277.     IconIndex = Index
  278.     iData.cbSize = Len(iData)
  279.     iData.hwnd = Picture1.hwnd
  280.     iData.uID = 9999
  281.     iData.uFlags = NIF_ICON
  282.     iData.uCallbackMessage = WM_LBUTTONDOWN
  283.     iData.hIcon = Image1(IconIndex).Picture
  284.     Result = Shell_NotifyIcon(NIM_MODIFY, iData)
  285. End Sub
  286. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  287.     Select Case x
  288.         Case TRAY_MSG_MOUSEMOVE
  289.         
  290.         Case TRAY_MSG_LEFTBTN_DOWN
  291.         
  292.         Case TRAY_MSG_LEFTBTN_UP
  293.             MyPopupmenu (x), (y)
  294.         Case TRAY_MSG_LEFTBTN_DBLCLICK
  295.             Me.Show
  296.             Me.SetFocus
  297.         Case TRAY_MSG_RIGHTBTN_DOWN
  298.         
  299.         Case TRAY_MSG_RIGHTBTN_UP
  300.             MyPopupmenu (x), (y)
  301.         Case TRAY_MSG_RIGHTBTN_DBLCLICK
  302.             
  303.     End Select
  304. End Sub
  305. Private Sub Timer1_Timer()
  306.     Dim iData As NOTIFYICONDATA
  307.     If chkFlash.Value = 1 Then
  308.     iData.cbSize = Len(iData)
  309.     iData.hwnd = Picture1.hwnd
  310.     iData.uID = 9999
  311.     If FlashOn Then
  312.         FlashOn = False
  313.         iData.uFlags = NIF_ICON
  314.         iData.hIcon = Image2.Picture
  315.         Result = Shell_NotifyIcon(NIM_MODIFY, iData)
  316.         
  317.     Else
  318.         iData.uFlags = NIF_ICON
  319.         iData.hIcon = Image1(IconIndex).Picture
  320.         Result = Shell_NotifyIcon(NIM_MODIFY, iData)
  321.         FlashOn = True
  322.     End If
  323.     Else
  324.         If FlashOn = False Then
  325.             
  326.             iData.cbSize = Len(iData)
  327.             iData.hwnd = Picture1.hwnd
  328.             iData.uID = 9999
  329.             iData.uFlags = NIF_ICON
  330.             iData.hIcon = Image1(IconIndex).Picture
  331.             Result = Shell_NotifyIcon(NIM_MODIFY, iData)
  332.             FlashOn = True
  333.         End If
  334.     End If
  335. End Sub
  336.